package com.bigfreakindeals.Application;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import org.apache.http.client.HttpClient;

import com.bigfreakindeals.R;
import com.bigfreakindeals.Protocols.SoapHandlers.FAQHandler;
import com.bigfreakindeals.R.drawable;
import com.bigfreakindeals.Common.Constant;
import com.bigfreakindeals.Common.Tools;
import com.bigfreakindeals.Controller.UIController;
import com.bigfreakindeals.Controller.ZipDownloader;
import com.bigfreakindeals.Models.Coupons;
import com.bigfreakindeals.Models.DiscussionComment;
import com.bigfreakindeals.Models.DrawableImageSlug;
import com.bigfreakindeals.Models.UniversityDeals;
import com.bigfreakindeals.Models.UserProfile;

import android.R.integer;
import android.app.Activity;
import android.app.Application;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


public class ApplicationEx extends Application {
	// Declare all global variables here
	public static final String BUILD_NUMBER = "001";
	public static final String VERSION_NUMBER = "1.00";
	private static final String BUILD_TRACKING = "000";
	public ArrayList<View> history;  
	public boolean isConfirm = false;
	public boolean onReceieveError = false;
	public boolean onDealsDropDown = false;
	
	public  int screenWidth;
	public   int screenHeight;
	public ProgressDialog progressDialog ;
	public byte getSchoolListCompletedStatus = 0;/*has not start = 0; ongoing =1 ; error = 2; done =3*/
	
	public UserProfile myProfile = new UserProfile();
	public HashMap<String, UniversityDeals> schoolListMap = new HashMap<String, UniversityDeals>();
	public List<String> schoolListString;
	private static ApplicationEx mInstance  = null;

	public  int currentTab = 0;
	
	public  boolean isUpdate = false;
	
	public  int currentTabState = 0;
	public  int STATE_ACTIVEDEALS = 0;
	public  int STATE_BUY = 1;
	public  int STATE_MYCOUPONS = 2;
	
	
	
	public Drawable activedeasl_DefaultBG_DRAKGRAY = null;
	public Drawable gradientGray_TOP_BOTTOM = null;
	public Drawable gradientGray_TOP_BOTTOM_BUTTON = null;
	public Drawable gradientGray_TOP_BOTTOM_ACTIVEDEALS= null;

	public Drawable gradientGray_TOP_BOTTOM_PAYPAL= null;

	public Drawable gradientGray_TOP_BOTTOM_BUY= null;
	public Drawable gradientGray_LEFT_RIGHT = null;
	
	public UIController controller;
	public Intent nodeasIntent;
	public String intent_label;
	public Bitmap mapDrawable;
	public int currentBG=0;
	
	public static boolean toPost = false;
	public String PayPal_dealId = null;
	public String PayPal_dealquantity= null;
	public ArrayList<DiscussionComment> commentList; 
	
	/*public List<String> commentNameList
	public List<String> commentAvatarList; 
	public List<String> commentMessageList; 
	public List<String> commentPostDateList; */
	public int commentCount;
	
	public HashMap<String, DrawableImageSlug> drawableImages = new HashMap<String, DrawableImageSlug>();
	
	
	@Override
	public void onCreate() {
		super.onCreate();
		
		mInstance = this;
		
		controller = new UIController();
		
		if (activedeasl_DefaultBG_DRAKGRAY == null)
			activedeasl_DefaultBG_DRAKGRAY = Tools.getDrawableButtonGeneric(new int[]{0xff575757, 0xff575757}, 0,GradientDrawable.Orientation.TOP_BOTTOM);
		
		if (gradientGray_TOP_BOTTOM == null)
			gradientGray_TOP_BOTTOM = Tools.getDrawableButtonGeneric(new int[]{0xffD9D9D9, 0xffFAFAFA}, 0,GradientDrawable.Orientation.TOP_BOTTOM);
		
		
		if (gradientGray_TOP_BOTTOM_BUY == null){
			Drawable drawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM , new int[]{0xffffffff,0xffffffff});
			int stroke = 1;/*stroke width*/
		
			((GradientDrawable)drawable).setCornerRadii(new float[] {10,10,10,10,10,10,10,10});
			((GradientDrawable)drawable).setStroke(stroke, 	0xff909090 );
			
			gradientGray_TOP_BOTTOM_BUY = drawable;
			
		
		}
		
		if (gradientGray_TOP_BOTTOM_BUTTON == null){
			
			Drawable drawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM , new int[]{0xffffffff,0xffffffff});
			int stroke = 1;/*stroke width*/
			
			((GradientDrawable)drawable).setCornerRadii(new float[] {10,10,10,10,10,10,10,10});
			((GradientDrawable)drawable).setStroke(stroke, 	0xff909090 );
			
			gradientGray_TOP_BOTTOM_BUTTON = drawable;
			
		}
		
		if (gradientGray_TOP_BOTTOM_PAYPAL == null){
			
			Drawable drawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM , new int[]{0xffD98719,0xFFE6B426});
			int stroke = 1;/*stroke width*/
			
			((GradientDrawable)drawable).setCornerRadii(new float[] {10,10,10,10,10,10,10,10});
			((GradientDrawable)drawable).setStroke(stroke, 	0xff909090 );
			
			gradientGray_TOP_BOTTOM_PAYPAL = drawable;
			
		}
		if (gradientGray_LEFT_RIGHT == null)
			gradientGray_LEFT_RIGHT = Tools.getDrawableButtonGeneric(new int[]{0xffe2e2e2, 0xffe2e2e2}, 0,GradientDrawable.Orientation.LEFT_RIGHT);
		
		if (gradientGray_TOP_BOTTOM_ACTIVEDEALS == null){
			
			Drawable drawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM , new int[]{0xfff2f2f2,0xffC2C2C2});
			int stroke = 1;/*stroke width*/
			
			((GradientDrawable)drawable).setCornerRadii(new float[] {0,0,0,0,10,10,10,10});
			((GradientDrawable)drawable).setStroke(stroke, 0xffC2C2C2);
			
			gradientGray_TOP_BOTTOM_ACTIVEDEALS = drawable;
		}
	}
	  public static ApplicationEx getInstance() {
          return mInstance;
      }
	 
	  
	  public Drawable getroundRect(){
		  Drawable drawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM , new int[]{0xffffffff,0xffffffff});
			int stroke = 1;/*stroke width*/
			
			((GradientDrawable)drawable).setCornerRadii(new float[] {10,10,10,10,10,10,10,10});
			((GradientDrawable)drawable).setStroke(stroke, 	0xff909090 );
			
			return drawable;
			
		  
	  }
	 
	  public void setHashBitmap(HashMap<String, Bitmap> hashmap, String slug){
		 
		  DrawableImageSlug drawableimageslug = new DrawableImageSlug(slug);
		  Bitmap bitmap;
		  Object[] keys =  hashmap.keySet().toArray();
		  for (int i = 0; i<keys.length;i++){
			 bitmap = (Bitmap)hashmap.get(keys[i]);
			 drawableimageslug.setdrawableImage(keys[i].toString(),bitmap);
		 }
		  //update universitydeals
		  //myProfile.getlastSelectedSchool().drawablImages = drawableimageslug;
		  
		  Log.i("setHashBitmap"," "+ slug);
			
		  drawableImages.put(slug, drawableimageslug);
		  
		}
	  
	  
	  public boolean addCouponThumnail(Bitmap bitmap,String dealID, int type){
		  if (myProfile.myCoupons!=null && myProfile.myCoupons.length>0){
			  System.out.println("addCouponThumnail...");
			  Coupons coupons;
			  for (int i = 0; i<  myProfile.myCoupons.length;i++){
				coupons = myProfile.myCoupons[i];
				if (coupons.dealID.compareTo(dealID) == 0){
					switch (type) {
					case 0:
						coupons.thumbnailsmall = Tools.getResizedBitmap(bitmap, 60, 60);
						break;
					case 1:
						coupons.thumbnailmedium = bitmap;
						break;
					case 2:
						coupons.thumbnaillarge = bitmap;
						break;
					default:
						break;
					}
					System.out.println(coupons.dealID+" "+coupons.thumbnailsmall+" "+coupons.thumbnailmedium+coupons.thumbnaillarge);
					myProfile.myCoupons[i] = coupons;
				}
			 }
			  
		  }return true;
	  }
	
}

